package com.geek.factory.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geek.factory.entity.PurchaseOrder;
import com.geek.factory.mapper.PurchaseOrderMapper;
import com.geek.factory.service.IPurchaseOrderService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-06-26
 */
@Service
public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, PurchaseOrder> implements IPurchaseOrderService {
    @Override
    public Map<String, Long> getPurchaseOrderStatusStats() {
        Map<String, Long> stats = new HashMap<>();

        // 待审核订单（包括 PENDING/pending）
        long pendingCount = this.count(new QueryWrapper<PurchaseOrder>()
                .lambda()
                .eq(PurchaseOrder::getStatus, "PENDING")
                .or()
                .eq(PurchaseOrder::getStatus, "pending"));
        stats.put("pendingReview", pendingCount);

        // 采购中订单（包括 PROCESSING/processing）
        long processingCount = this.count(new QueryWrapper<PurchaseOrder>()
                .lambda()
                .eq(PurchaseOrder::getStatus, "PROCESSING")
                .or()
                .eq(PurchaseOrder::getStatus, "processing"));
        stats.put("inProgress", processingCount);

        return stats;
    }
}
